﻿<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <title>个人中心 - 橘子财税，办税不累</title>
    <link rel="shortcut icon" href="static/images/logo.jpg" type="image/x-icon"/>
    <link href="./static/css/app.aa50d7a1e10eaca07f2a864238d3577a.css" rel="stylesheet"/>
    <script type="text/javascript" src="static/js/vue.js"></script>
    <script type="text/javascript" src="static/js/axios.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        .hover-list{
            display: block;
            color: #666;
        }
        .hover-list:hover{
            cursor: pointer;
            color: #72b1ff;
        }
        .el-table{
            color: #999;
        }
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
    </style>
</head>
<body>
<div id="app">
    <div id="header">
        <div class="header">
            <a href="http://www.caishuib.com">
                <img src="static/images/logo.jpg" alt="橘子财税" class="logo">
            </a>
            <ul class="menu">
                <li class=""><a href="people.html" style="color: #fff;display: block;height: 100%;width: 100%;">首页</a> <img
                        src=""
                        class="triangle-tips"/></li>
                <li class=""> <a href="changePass.html" style="color: #fff;display: block;height: 100%;width: 100%;">账户设置</a>  <img
                        src=""
                        class="triangle-tips"/></li>
            </ul>
            <a href="http://xiaopengbest.cn/index.html" class="toindex">叮叮财税首页</a>
            <a class="outlogin" @click="loginOut">退出登录</a>
        </div>
    </div>
    <div id="body">
        <div>
            <div class="Sidebar">
                <div class="content">
                    <p class="title">账号管理</p>
                    <div>
                        <a href="people.html" class="router-link-exact-active router-link-active">个人资料</a>
                    </div>
                    <div>
                        <a href="changePass.html" class="">密码修改</a>
                    </div>
                </div>
                <div class="content">
                    <p class="title">收藏记录</p>
                    <div>
                        <a href="shouCang.html" class="">我的收藏</a>
                    </div>
                </div>
                <div class="content">
                    <p class="title">历史记录</p>
                    <div>
                        <a href="home.html" >咨询记录</a>
                    </div>
                    <div>
                        <a href="keChengJiLu.html" >课程记录</a>
                    </div>
                </div>
            </div>
            <div id="main">
                <div id="title">
                    <span class="title">咨询记录</span>
                </div>
                <div id="content">
                    <div class="comment1" v-loading="loadings"  element-loading-text="用户信息获取中">
                        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                            <el-form-item label="昵称" prop="name">
                                <el-input type="text" v-model="ruleForm.name" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="头像" prop="icon">
                                <el-upload v-loading="loadingDialig"
                                           class="avatar-uploader"
                                           action="123"
                                           :show-file-list="false"
                                           :before-upload="beforeAvatarUpload">
                                    <img v-if="ruleForm.icon" :src="ruleForm.icon" class="avatar">
                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                </el-upload>
                            </el-form-item>
                            <el-form-item style="text-align: center">
                                <el-button type="primary" :loading="loading" @click="submitForm('ruleForm')">{{loading?'修改中':'修改'}}</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="https://hm.baidu.com/hm.js?a71c3d484b2419b0d94468789f7f49e1"></script>
<script type="text/javascript">var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?a71c3d484b2419b0d94468789f7f49e1";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>

</body>
<script type="text/javascript">
    new Vue({
        el: '#app',
        data: {
            loadingDialig:false,
            pageInfo: {
                per_page: 6,
                total: 0,
                current_page: 1
            },
            ruleForm: {
                name: '',
                icon:''
            },
            rules:{
                name: [{ required: true, message: '请填写昵称', trigger: 'change' }],
                icon: [{ required: true, message: '请上传头像', trigger: 'change' }]
            },
            contentData: [],
            token: '',
            userPhone: '',
            loadings: false,
            loading: false,
            userInfo: {},
            peopleHttp: 'http://xiaopengbest.cn/api/common/user/',
            uploadHttp: 'http://xiaopengbest.cn/api/admin/common/uploadInfo'
        },
        watch: {
            loginDialogVisible: function (val) {
                if (!val) {
                    Object.keys(this.form).forEach(key => this.form[key] = '');
                    this.$refs['form'].resetFields();
                }
            },
            isLogin: function (val) {
                if (val) {
                    this.title = '登录';
                } else {
                    this.title = '注册';
                }
            }
        },
        created() {
            this.token = localStorage.getItem('token');
            if(this.token){
                this.token =(this.token.replace('"',''));
            }
            this.userPhone = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')).phone : '';
            this.userInfo = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : '';
            this.ruleForm.name = this.userInfo.name;
            this.ruleForm.icon = this.userInfo.icon;
            this.peopleHttp = this.peopleHttp + this.userInfo.id
        },
        methods: {
            beforeAvatarUpload (file) {
                var fileName=new Array()
                fileName =file.name.split('.');
                const extension = fileName[fileName.length-1] === 'jpg'
                const extension2 =  fileName[fileName.length-1]=== 'png'
                if (!extension && !extension2) {
                    this.$message({
                        message: '上传模板只能是jpg、png格式!',
                        type: 'warning'
                    });
                }
                if (extension || extension2) {
                    let fd = new FormData();
                    fd.append('fileUpload', file)
                    this.newImport(fd);
                }
                return false;
            },
            newImport (data) {
                let config = {
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                        'Authorization' : 'Bearer' + this.token
                    }
                };
                this.loadingDialig = true;
                axios.post(this.uploadHttp, data,config)
                    .then((res) => {
                        this.ruleForm.icon = res.data.data.path;
                        this.loadingDialig = false;
                    })
                    .catch((err) => {
                        this.loadingDialig = false;
                        this.$message.warning(err.response.data.msg || "数据异常，请重试");
                    })
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.changePeople();
                    } else {
                        return false;
                    }
                });
            },
            loginOut() {
                localStorage.clear();
                // window.location.href = 'http://localhost:63342/vueding/index.html';
                window.location.href = 'http://xiaopengbest.cn/index.html';
            },
            changePeople() {
                this.loading = true;
                axios.put(this.peopleHttp, {
                    name:this.ruleForm.name,
                    icon:this.ruleForm.icon
                },{
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
                        'Authorization': 'Bearer ' + this.token
                    },
                    transformRequest: [function (data) {
                        let ret = '';
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }]
                }).then((res) => {
                    if (res.data.code == 200) {
                        this.$message({
                            message:'资料修改成功',
                            duration: 1000,
                            type:'success'
                        });
                    }
                    localStorage.setItem('userInfo',JSON.stringify(res.data.data));
                    this.loading = false;
                }).catch((err) => {
                    this.loading = false;
                    this.$message.warning(err.response.data.msg || "数据异常，请重试");
                });
            }
        }
    });
</script>
</html>
